<?php
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */

class b2c_ctl_admin_goods_freight extends desktop_controller{
    var $workground = 'b2c_ctl_admin_goods';

    public function __construct($app){
        parent::__construct($app);
        header("cache-control: no-store, no-cache, must-revalidate");
    }

    function index(){
        $custom_actions[] = array('label'=>app::get('b2c')->_('添加'),'href'=>'index.php?app=b2c&ctl=admin_goods_freight&act=add','target'=>'dialog::{title:\''.app::get('b2c')->_('添加相关运费').'\',width:400,height:200}');
		$actions_base['use_buildin_recycle'] = true;
        $actions_base['title'] = app::get('b2c')->_('相关运费');
        $actions_base['actions'] = $custom_actions;
        $this->finder('b2c_mdl_goods_freight',$actions_base);
    }
    function add(){
        if($this->has_permission('editgoods')){
			$this->display('admin/goods/freight_edit.html');
		}
    }
    function edit($freight_id){
        if($this->has_permission('editgoods')){
			$row=app::get('b2c')->model('goods_freight')->getRow('*',array('freight_id'=>$freight_id));
			$this->pagedata['freight']=$row;
			$this->display('admin/goods/freight_edit.html');
		}
    }

    function toggle($freight_id){
        $this->begin('index.php?app=b2c&ctl=admin_goods_freight&act=index');

        if ($this->has_permission('editgoods')) {
            $res=app::get('b2c')->model('goods_freight')->getRow('*',array('freight_id'=>$freight_id));
            $mdl_goods_freight=app::get('b2c')->model('goods_freight');

            if ($res['freight_toggle'] == 0) {
                $mdl_goods_freight->update(array('freight_toggle'=>1),array('freight_id'=>$freight_id));
            } else {
                $mdl_goods_freight->update(array('freight_toggle'=>0),array('freight_id'=>$freight_id));
            }
        }
        $this->end(true,app::get('b2c')->_('设置成功'));


    }

    function save(){
        if($this->has_permission('editgoods')){
			$freight['freight_id']=$_POST['freight_id'];
			$freight['freight_explain']=$_POST['freight_explain'];
			$this->begin('index.php?app=b2c&ctl=admin_goods_freight&act=index');
			$mdl_goods_freight=app::get('b2c')->model('goods_freight');
			if($mdl_goods_freight->save($freight)){
				$this->end(true,app::get('b2c')->_('保存成功'));
			}else{
				$this->end(false,app::get('b2c')->_('保存失败'));
			}

		}
    }
}
